home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / HELPME.PAK / HELPME.WRI
Text File  |  1997-05-06  |  61KB  |  1,493 lines

  1. ****************************************
  2. BORLAND C++: ANSWERS TO COMMON QUESTIONS
  3. ****************************************
  4.  
  5. This file contains information about the following issues:
  6.  
  7.      * Getting Started
  8.      * Exception Handling
  9.      * Other Common C++ Questions
  10.      * Common Windows and ObjectWindows Questions
  11.      * Integrated Environment and Resource Workshop
  12.      * Command-Line Compilers
  13.      * General I/O
  14.      * Graphics (DOS)
  15.      * Math and Floating Point
  16.      * Linker Errors
  17.      * Other Questions
  18.  
  19. Getting Started
  20. ---------------------------------------------------------------
  21. Q. How do I install Borland C++?
  22. A. For help on a wide range of common installation issues, see
  23.    the online document, INSTALL.TXT.
  24.  
  25. Q. What is a configuration file?
  26. A. A configuration file tells Borland C++ what options to use as
  27.    defaults and where to look for its library and header files.
  28.    BCC.EXE looks for a file named TURBOC.CFG, and BCC32.EXE
  29.    looks for a file named BCC32.CFG. The integrated environment,
  30.    BCW.EXE, looks for the following default configuration files:
  31.    BCCONFIG.BCW, BCWDEF.BCW and BCWDEF.DSW.
  32.  
  33. Q. How do I create a configuration file?
  34. A. The INSTALL program creates TURBOC.CFG and BCC32.CFG for you.
  35.    These file are ASCII files you can change with any text editor.
  36.    They contain path information for the library and header files
  37.    used by BCC.EXE and BCC32.EXE, respectively. In the case of
  38.    the IDE (BCW.EXE), configuration files are created the first
  39.    time you start the IDE. They are saved automatically each time
  40.    you exit. You can turn this autosave feature off by selecting
  41.    Options|Environment|Preferences. You can also explicitly save
  42.    your options using Options|Save. The options listed on this
  43.    menu and the files they correspond to are as follows:
  44.  
  45.     Menu Option      File in BIN directory
  46.     ===========      =====================
  47.     Environment      BCCONFIG.BCW
  48.     Desktop          BCWDEF.DSW
  49.     Project          BCWDEF.BCW
  50.  
  51. Q. What is project file or configuration file corruption?
  52. A. Project file corruption occurs when an error occurs during
  53.    program development and a "bad" portion of memory gets saved
  54.    to disk. This can later cause problems in the IDE. You might
  55.    suspect that your project files have become corrupt if you
  56.    experience strange new behavior either when compiling or
  57.    linking or if you are running very simple programs which
  58.    don't behave as you would expect them to.
  59.  
  60.    If you suspect that your project files have become corrupt,
  61.    exit the IDE and delete the default IDE configuration files
  62.    that are listed above.
  63.  
  64.    You'll also want to check the files that the IDE uses for
  65.    your specific project. This is especially true if the trouble
  66.    you're having seems to happen in one project only.
  67.    First, note what files are included in your project and what
  68.    settings they use. Next, make a backup copy of your project
  69.    file (.IDE) so that you can refer to it if needed (use the DOS
  70.    COPY command). Give the backup an extension other than .IDE or
  71.    .PRJ (.BAK is a good extension). Also look in your project
  72.    directory for files with the same base file name as your
  73.    project and with the extension of .BCW or .DSW . Delete or
  74.    back up these files as well.
  75.  
  76.    Once you have deleted or renamed the default configuration
  77.    files and the files associated with your particular project,
  78.    rebuild your project and try running your program again. If
  79.    you're still having problems contact Borland Technical Support.
  80.  
  81. Q. How can I prevent project file corruption?
  82. A. One way to help minimize the chance of corruption is to
  83.    turn off the autosave feature by selecting
  84.    Options|Environment|Preferences and unchecking the autosave
  85.    checkboxes. If you do this before you exit the IDE each
  86.    time, you'll need to explicitly save your project and options
  87.    using Options|Save. Don't save the files if you experience
  88.    any problems in the course of development.
  89.  
  90.  
  91. Exception Handling
  92. ------------------------------------------------------------
  93. Q. How do I prevent the debugger from catching exceptions?
  94. A. Go to the local option of Module View (press Alt+F10 or
  95.    right-click in a Module View window). Press 'X' for
  96.    Exceptions. Press 'N' to turn off C++ exceptions and 'o'
  97.    to turn off C exceptions. Note that both types of
  98.    exceptions must be disabled in order to stop the debugger
  99.    from trapping exceptions.
  100.  
  101. Q. How do I step into the catch block of an exception?
  102. A. You don't have to do anything special if you step over
  103.    the throw() statement with either F7 or F8. You won't
  104.    be able to step directly into the catch block if you
  105.    step over a function which contains a throw statement.
  106.    What you will have to do is place a breakpoint in the
  107.    desired catch block. Note that this is what happens
  108.    when attempting to step through new--the new default
  109.    behavior of new is to throw an exception, xalloc,
  110.   when an allocation fails.
  111.  
  112. Q. Why is the new operator behaving differently?
  113. A. The default behavior of new in BC 5.0 is to throw
  114.    an exception, xalloc, if the allocation fails. A NULL
  115.    value is no longer returned. The current error
  116.    checking for new should look something like this:
  117.     char *temp;
  118.     try
  119.     {
  120.          temp = new char[20];
  121.     }
  122.     catch(xalloc)
  123.     {
  124.    // Do error handling here; possibly assign NULL to temp
  125.     }
  126.  
  127. Q. How do I disable exception handling when using operator new?
  128. A. Refer to the following example:
  129.  
  130.    #include <iostream.h>
  131.    #include <except.h>
  132.    #include <new.h>
  133.  
  134.    int
  135.    main() {
  136.        set_new_handler(0);        // comment out to use exceptions
  137.        try {
  138.        char *p;
  139.        while (1) {        // exhaustively allocate heap
  140.            const unsigned k = 1024;
  141.            const unsigned n = 100 * k;
  142.            p = new char[n];
  143.            if (!p)
  144.            break;
  145.        }
  146.        cerr << "detected via pointer value" << endl;
  147.        }
  148.        catch(const xalloc&) {
  149.        cerr << "detected via exception" << endl;
  150.        }
  151.        return 0;
  152.    }
  153.  
  154. Q. How can I change the default behavior of new for global
  155.    objects? For example, where a global instance of a
  156.    class calls new within its constructor?
  157. A. Global objects are created before execution gets to the
  158.    main function. Set up a startup function which gets
  159.    called before the global objects are created. This 
  160.    is done using the #pragma startup statement:
  161.     #include <new.h>
  162.     void set_new(void)
  163.     {
  164.       set_new_handler(0) ;
  165.     }
  166.     // global objects are created with a priority of 32,
  167.     // so use 31 as the priority for the function so that
  168.       // it gets called before global objects are created.
  169.     #pragma startup set_new 31
  170.  
  171. Q. How do I catch exceptions that are not explicitly
  172.    handled by a catch block so that abort isn't
  173.    automatically called?
  174. A. Add a catch block which has ellipses as its
  175.    parameter to every try block:
  176.     try
  177.     {
  178.       throw(1);
  179.     }
  180.     catch(...)
  181.     {
  182.       cout << "All exceptions are caught" << endl;
  183.     }
  184.  
  185.    This ensures that there are no unhandled exceptions.
  186.  
  187. Q. What are some of the predefined exceptions that can
  188.    be thrown?
  189. A. There are a number of exception which are thrown from
  190.    Borland functions (most of which are described in
  191.    the Library Reference):
  192.       xalloc     - thrown from new.
  193.       Bad_cast   - thrown from dynamic_cast
  194.       Bad_typeid - thrown when the operand of typeid 
  195.                    is a dereferenced 0 pointer.
  196.  
  197. Q. How can I display information when an exception
  198.    goes unhandled?
  199. A. The exception handling mechanism calls the
  200.    terminate() function before calling abort(). This
  201.    function does nothing by default, but a new function
  202.    can be set using the set_terminate() function. The
  203.    set_terminate() function takes as a parameter a
  204.    function which returns void and does not take any
  205.    parameters (void). You can display error messages
  206.    within this function:
  207.      #include <except.h>
  208.      #include <new.h>
  209.      #include <iostream.h>
  210.  
  211.      void term_func(void)
  212.      {
  213.      cout << "This exception went unhandled:" << endl;
  214.      cout << "  Name: " << __throwExceptionName << endl;
  215.        // The following information is only valid if the
  216.        // -xp (Enable exception location Information)
  217.        // compiler switch was set. Under Options|Project|
  218.        // C++ Options in the IDE.
  219.      cout << "  FileName: " << __throwFileName << endl;
  220.      cout << "  LineNumber: " << __throwLineNumber << endl;
  221.      exit(3);
  222.      }
  223.  
  224.      int main(void)
  225.        {
  226.        set_terminate(term_func);
  227.        return 0;
  228.        }
  229.  
  230.   Note that you have to call exit() from the terminate
  231.   function in order to prevent the abort() function from
  232.   being called (which in turn displays the "Abnormal Program
  233.   Termination" message).
  234.  
  235. Q. How can I get information about an exception?
  236. A. The object you throw can contain information that
  237.    can be accessed within the catch block. You can also
  238.    get information about where an exception was thrown
  239.    by the use of certain global variables:
  240.    __throwExceptionName, __throwFileName, and
  241.    __throwLineNumber. These variables are documented in
  242.    the Library Reference. Note that you have
  243.    to have 'Enable Exception Location Information' set
  244.    in order to get the FileName and LineNumber (-xp from
  245.    the command line, Options|Project|C++ Options in the
  246.    IDE.) The following shows a simple method of getting
  247.    additional information from an xalloc exception (which
  248.    is thrown by new):
  249.      #include <cstring.h>
  250.      #include <except.h>
  251.  
  252.       int main(void)
  253.      {
  254.       char huge *temp;
  255.       try
  256.        {
  257.        temp = new huge char[1000000Ul]; // This will fail in DOS
  258.        delete temp;
  259.        }
  260.       catch(xalloc one)
  261.       {
  262.        cout << "Allocation failed in main" << endl;
  263.        cout << one.why().c_str() << endl;
  264.        cout << "  Name: " << __throwExceptionName << endl;
  265.          // The following information is only valid if the
  266.          // -xp (Enable exception location Information)
  267.          // compiler switch was set. Under Options|Project|
  268.          // C++ Options in the IDE.
  269.        cout << "  FileName: " << __throwFileName << endl;
  270.        cout << "  LineNumber: " << __throwLineNumber << endl;
  271.        }
  272.       catch(...)
  273.       {
  274.        cout << "An unhandled exception occurred" << endl;
  275.       }
  276.       return 0;
  277.      }
  278.  
  279.    The xalloc class contains a member function, why()
  280.    that returns a cstring object. The cstring class has a
  281.    function, c_str(), which returns a char *.
  282.  
  283. Q. Why does my application abort and get an "Abnormal Program
  284.    Termination" message?
  285. A. When an exception is thrown within an application but
  286.    isn't caught, first the terminate() and then the abort()
  287.    functions are called. It's the abort() function that
  288.    displays the "Abnormal Program Termination"  message.
  289.    You can use the set_terminate() function to replace the
  290.    existing terminate function (the terminate() function
  291.    does nothing by default, but can be modified to display
  292.    a message). Note that you need to call exit() from
  293.    within the terminate() function if you don't want the
  294.    "Abnormal Program Termination" message displayed. For
  295.    more information, go to the section "How do I display
  296.    information when an exception goes unhandled?"
  297.  
  298.    Note that the new operator aborts on failure if the
  299.    xalloc exception isn't caught.
  300.  
  301. Q. Why is my program aborting with the "Abnormal Program 
  302.    Termination" message after I have turned off exception
  303.    handling (-x-) for my modules?
  304. A. The behavior of operator new failures isn't changed by 
  305.    turning off exceptions within your modules, because an 
  306.    exception (xalloc) is still being thrown.  Unless this exception 
  307.    is caught, abort() will ultimately be called (hence the "Abnormal
  308.    Program Termination" error...).  To modify what happens when 
  309.    operator new fails, use the set_new_handler() function call.  
  310.    Calling set_new_handler(0) with zero as an argument disables an 
  311.    instance of xalloc from being thrown and 0 will be returned from 
  312.    the call to operator new.
  313.  
  314. Q. Why does my application terminate when throwing an
  315.    exception from within a destructor?
  316. A. What is most likely happening is that the exception
  317.    is thrown while the compiler is cleaning up the stack
  318.    from a previously thrown exception. The compiler 
  319.    automatically cleans up objects on the stack when an
  320.    exception is thrown. These objects on the stack can
  321.    have destructors, which are also automatically called
  322.    by the exception mechanism. Throwing an exception at
  323.    any time within this cleanup isn't allowed.
  324.  
  325. Q. How do I pass an exception up the chain if I have
  326.    nest try...catch blocks?
  327. A. Using throw without any parameters within a catch block
  328.    throws the exception up the chain:
  329.     try
  330.     {
  331.        try
  332.        {
  333.          throw(10);
  334.        }
  335.        catch(int i)
  336.        {
  337.         cout << "Caught exception: " << i << endl;
  338.         throw;
  339.        }
  340.     }
  341.     catch(int i)
  342.     {
  343.       cout << "Caught Exception: " << i << " again." << endl;
  344.     }
  345.  
  346. Q. Where can I get more information regarding exceptions?
  347. A. Exceptions are covered in the following books:
  348.    "The Borland C++ 5.0 Programmers Guide"
  349.    "The Annotated C++ Reference Manual" by Ellis and
  350.     Stroustrup, from Addison-Wesley Publishing Company.
  351.    "The C++ Programming Language, Second Edition" by
  352.     Bjarne Stroustrup, from Addison-Wesley publishing Company.
  353.  
  354. Other Common C++ Questions
  355. ------------------------------------------------------------
  356. Q. When linking C or Assembly language modules with C++
  357.    modules I get undefined symbol errors at link time. It
  358.    appears that none of the C or Assembly public symbols
  359.    can be found.
  360. A. Because of function and member function overloading prescribed 
  361.    by the C++ language, Borland C++ must internally attach 
  362.    information to function names and variables (name mangling) 
  363.    to maintain uniqueness.  Automatic name mangling generates 
  364.    names which do not conform to standard C names.  Name mangling
  365.    can be disabled by using the 'extern "C"' modifier;  any name
  366.    having name mangling disabled will result in a standard C name.
  367.    This is the common manner in which C modules can be linked 
  368.    into C++ applications.  For example:
  369.  
  370.    in C module:
  371.        int foo(char *p)  { /* ... */ }
  372.  
  373.    in C++ module:
  374.        extern "C" int foo(char*);
  375.        int main() {
  376.            foo("Hello, world!");
  377.            return 0;
  378.        }
  379.  
  380.    In this example, the code for function foo() is compiled as a 
  381.    C module. By declaring the function prototype within the C++ 
  382.    module as 'extern "C"', Borland C++ will not mangle the name in 
  383.    the call to the function.  Upon linking, the linker will be able 
  384.    to resolve both the C code and call found in function main().   
  385.  
  386.    See related comments under Linker Errors. There is also
  387.    more on extern "C" in the Programmer's Guide.
  388.  
  389. Q: How can I allocate a doubly-dimensioned array?
  390. A: You can use either malloc() with C or C++, or the
  391.    new operator with C++:
  392.     malloc():  to create a 2 by 3 character array
  393.         int i;
  394.         char** p;
  395.         p = (char **) malloc(2);
  396.         for (i=0; i<2; i++) p[i] = (char *) malloc(3);
  397.     new:
  398.         int j;
  399.         char** q;
  400.         q = new char* [2];
  401.           for (j=0; j<2; j++) q[j] = new char [3];
  402.  
  403. Q. Classes with static data members are getting linker
  404.    errors ("undefined").
  405. A. Given the example:
  406.  
  407.    class foo {
  408.        static int i;
  409.    };
  410.  
  411.    Remember that this is only a declaration and not a 
  412.    definition for integer i.  To allocate memory for i, 
  413.    define all static members at file scope with or without 
  414.    initialization.  For example:
  415.  
  416.    int foo::i = 0;
  417.    int main() {
  418.        foo f;
  419.        // ...
  420.        return 0;
  421.    }
  422.  
  423.    For a definitive discussion, see section 9.4 of the ARM 
  424.    or 9.4.2 of the September WP.  
  425.  
  426.    In the case of a template class, you need to similarly define 
  427.    static data outside the class definition, and also include the 
  428.    actual type information for any type you plan to instantiate the
  429.    template class with. For example:
  430.  
  431.    template <class T>
  432.    class bar {
  433.        static int i;
  434.    };
  435.  
  436.    bar<int>::i;      // provide definition for an integer template
  437.                      //  class instantiation type
  438.    bar<Myclass>::i;  // provide definition for a user-defined type
  439.                      // template class instantiation
  440.  
  441. Q. What potential problems can arise from typecasting a
  442.    base class pointer into a derived class pointer so that
  443.    the derived class's member functions can be called?
  444. A. Syntactically this is allowable. There is always the
  445.    possibility of a base pointer actually pointing to a
  446.    base class. If this is typecast to a derived type,
  447.    the function being called might not exist in the base
  448.    class. Therefore, you would be grabbing the address of
  449.    a function that doesn't exist.
  450.  
  451. Q: What is the difference between the keywords "struct" and "class"?
  452. A: The members of a "struct" are "public" by default, while
  453.    in a C++ class, they are by default "private".  They are
  454.    otherwise functionally equivalent.
  455.  
  456. Q: I declared a derived class from a base class, but
  457.    I can't access any of the base class members with the
  458.    derived class function.
  459. A: Derived classes DO NOT get access to private members
  460.    of a base class. In order to access members of a base
  461.    class, the base class members must be declared as either
  462.    public or protected. If they are public, then any
  463.    portion of the program can access them. If they are
  464.    protected, they are accessible by the class members,
  465.    friends, and any derived classes.
  466.  
  467. Q: I have a class that is derived from three base classes.
  468.    Can I ensure that one base class constructor will be
  469.    called before all other constructors?
  470. A: If you declare the base class as a virtual base class,
  471.    its constructor will be called before any non-virtual
  472.    base class constructors. Otherwise the constructors
  473.    are called in left-to-right order on the declaration
  474.    line for the class.
  475.  
  476. Q: Are the standard library I/O functions still available
  477.    for use with the C++ iostreams library?
  478. A: Yes, using  #include <stdio.h> functions such as
  479.    printf() and scanf() are available. However, using
  480.    them in conjunction with stream-oriented functions
  481.    can lead to unpredictable behavior.
  482.  
  483. Q. In C++, given two variables of the same name, one local
  484.    and one global, how do I access the global instance
  485.    within the local scope?
  486. A. Use the scope (::) operator. For example:
  487.        int x = 10;
  488.        for(int x=0; x < ::x; x++)
  489.        {
  490.           cout << "Loop # " << x << "\n"; 
  491.           // This will loop 10 times
  492.        }
  493.  
  494. Q. If I pass a character to a function which only
  495.    accepts an int, what will the compiler do? Will
  496.    it flag it as an error?
  497. A. No. The compiler promotes the char to an int and uses
  498.    the integer representation in the function instead of
  499.    the character itself. The exception here is in the
  500.    case of a template function where no implicit
  501.    conversions or promotions take place.
  502.  
  503. Q. I was trying to allocate an array of function pointers
  504.    using the new operator but I keep getting declaration
  505.    syntax errors using the following syntax:
  506.    new int(*[10])();   What's wrong?
  507. A. The new operator is a unary operator and binds first
  508.    to the int keyword producing the following:
  509.     (new int) (*[10])();
  510.    You need to put parentheses around the expression to
  511.    produce the expected results:
  512.     new (int (*[10]()); //array of function pointers
  513.  
  514. Q. What are inline functions? What are their advantages?
  515.    How are they declared?
  516. A. An inline function is a function that gets textually
  517.    inserted by the compiler, much like a macro. The
  518.    advantage is that execution time is shortened because
  519.    linker overhead is minimized. They are declared by using
  520.    the inline keyword when the function is declared:
  521.   inline void func(void) {cout << "printing inline function \n";}
  522.    or by including the function declaration and code body
  523.    within a class:
  524.      class test
  525.      {
  526.      public:
  527.      void func(void) {cout << "inline function within a class.\n"}
  528.      };
  529.  
  530. Q. If I don't specify either public or private sections
  531.    in a class, what is the default?
  532. A. In a class, all members are private by default if neither
  533.    public nor private sections are declared.
  534.  
  535. Q. If I don't specify either the public or private keyword when
  536.    inheriting from a base class, what is the default?
  537. A. In Borland C++ 2.0, the default was public inheritance,
  538.    but in versions 3.0 through 5.0, the default is private
  539.    inheritance.
  540.  
  541. Q. What does the _seg modifier do?
  542. A. Using _seg causes a pointer to become a storage place for a
  543.    segment value, rather than an offset (or a segment/offset).
  544.    For instance, if "int _seg *x" contains the value 0x40,
  545.    then when you use "*x", the value pointed to will be at
  546.    segment 0x40, offset 0. If you add a value to the pointer,
  547.    the value is multiplied by the size of the pointer type. That
  548.    new value is used as an offset and is combined with the
  549.    segment value contained in the pointer. For example,
  550.        int _seg *x;
  551.        int value;
  552.  
  553.        x = (int _seg *)0x40;
  554.        value = *(x + 20);
  555.  
  556.    value is assigned the value of the integer at 0x40:0x28
  557.    (Remember, 20 * sizeof(int) = 40 = 0x28).
  558.    You can find a more detailed description of _seg in the
  559.    Borland C++ DOS Reference.
  560.  
  561. Q. Can I statically allocate more than 64K of data in
  562.    a single module?
  563. A. Yes. Far data items are now supported:
  564.        ...
  565.        char far array1[60000L];
  566.        char far array2[60000L];
  567.        ...
  568.     For arrays larger than 64k use:
  569.        char huge array3[100000L];
  570.  
  571. Q. What is a friend member function?
  572. A. Declaring a friend gives non-members of a class access
  573.    to the non-public members of a class.
  574.  
  575. Q. Why do I get a "Type name expected" error on my definition
  576.    of a friend class in my new class?
  577. A. You need to let the compiler know that the label you use
  578.    for your friend class is another class. If you don't
  579.    want to define your entire class, you can simply have
  580.    "class xxx", where xxx is your label. For example:
  581.      class Myclass1; //forward class declaration is required
  582.  
  583.     class Myclass2{
  584.           friend class Myclass1;
  585.           ...
  586.     };
  587.  
  588. Q: How can I output hex values in uppercase using the
  589.    iostream libraries?
  590. A: You need to set the state of the stream using setf().
  591.    For example,
  592.       #include <iostream.h>
  593.       int main()
  594.       {
  595.         cout << hex;
  596.         cout << "\nNot upper-case : " << 255;
  597.         cout.setf(ios::uppercase);
  598.         cout << "\nUppercase     : " << 255;
  599.         return 0;
  600.       }
  601.  
  602. Q: The following program compiles/links successfully in
  603.    C but not in C++. Why?
  604.     #include <stdlib.h>
  605.  
  606.     int compare(const int *one, const int *two)
  607.     {
  608.        if (*one > *two)
  609.           return  -1;
  610.        else
  611.           return 1;
  612.     }
  613.     int a[3] = { 50, 10, 20 };
  614.  
  615.     void main()
  616.     {
  617.          qsort(a, 3, sizeof(a[0]), compare);
  618.     }
  619. A: The fourth parameter to compare is the function
  620.    pointer, and here's how it's declared in stdlib.h:
  621.    void qsort (void *__base, size_t __nelem, size_t __width,
  622.            int _Cdecl (*__fcmp)(const void *, const void *));
  623.  
  624.    However, the above program WILL NOT compile in C++,
  625.    because of the strong typing features of the C++
  626.    language. The compiler refuses to convert the void
  627.    parameters in the declaration to __fcmp function to
  628.    int parameters. However, because C++ permits casting
  629.    of function pointers, you can fix the call to QSORT
  630.    in C++ like this:
  631.     qsort(a, 3, sizeof(a[0]), 
  632.           (int (*)(const void *,const void *))compare);
  633.  
  634.    By casting the COMPARE function to be of the same type
  635.    as the declaration in stdlib.h, C++ will accept and
  636.    compile it.
  637.  
  638. Q. What is the "this" pointer?
  639. A. "this" is a local variable in the body of a non-static
  640.    member function. It is a pointer to the object for
  641.    which the function was started. It cannot be used
  642.    outside of a class member function body.
  643.  
  644. Q. Why does a binary member function only accept a
  645.    single argument?
  646. A. The first argument is defined implicitly.
  647.  
  648. Q. Looking through the class libraries there are
  649.    definitions in classes which look like:
  650.        class test {
  651.            int funct(void) const;
  652.        };
  653.     What is the const keyword doing here?
  654. A. Using the keyword "const" after the parameter list 
  655.    designates that the member function is to be a constant 
  656.    member function.  Constant member functions should not 
  657.    modify class data, and the compiler should verify that no 
  658.    attempt is being made to change the value of a member 
  659.    within the scope of the member function.
  660.  
  661. Q. Is there any object similar to "cout" that will receive 
  662.    all printer output?
  663. A. According to the C++ language, no.  However, you can create 
  664.    your own object that will be connected to the standard 
  665.    DOS printer handle 4 as follows:
  666.  
  667.    #include <fstream.h>
  668.    #include <stdio.h>
  669.    ofstream cprn(fileno(stdprn));
  670.    int main() {
  671.        cprn << "Hello, world!" << endl;
  672.        return 0;
  673.    }
  674.  
  675. Q: How can I use _new_handler and set_new_handler?
  676. A: Borland C++ supports _new_handler and set_new_handler.
  677.    You can find a discussion of them in the
  678.    Borland C++ Programmer's Guide. The type of _new_handler
  679.    is as follows.
  680.       typedef void (*vfp)(void);
  681.       vfp _new_handler;
  682.       vfp set_new_handler(vfp);
  683.  
  684. Q: I would like to use C++ fstreams on a file opened
  685.    in binary mode. How is this done?
  686. A: Use ios::binary as the open mode for the file:
  687.       #include <fstream.h>
  688.       ifstream binfile;
  689.       binfile.open("myfile.bin", ios::binary);
  690.  
  691. Q: How can I get at the DOS file handle associated
  692.    with my iostream?
  693. A: Using a combination of member functions fd() and
  694.    rdbuf() you can get at the file handle.
  695.       #include <fstream.h>
  696.       #define fstrno(s)  (((s).rdbuf())->fd())
  697.       ifstream test("test.txt");
  698.       cout << "handle is " << fstrno(test) << '\n';
  699.  
  700. Q: How can I increase the number of FILES available to
  701.    my program under Borland C++ 5.0?
  702. A: Increasing the number of available files involves
  703.    changing the following 3 files located in the Run-Time
  704.    Library: _NFILE.H, FILES.C, and FILES2.C. For
  705.    instructions on how to do this, download TI870 from 
  706.    the Borland fax line.
  707.  
  708. Q: When using the BIDS library, if I try to create an
  709.    Array or Bag of integers, I get the error "multiple
  710.    declaration for detach()...".
  711. A: If you try to create a TI_ArrayAsVector<int>, 
  712.    TI_SArrayAsVector<int>, or TI_BagAsVector<unsigned>,
  713.    the compiler yields an error message. This is because
  714.    each of these templates provides a version of detach()
  715.    that takes an argument whose type is the type for
  716.    which the template is being instantiated, plus a
  717.    version that takes an argument of type int or
  718.    unsigned int, which lets you specify the index for the
  719.    item to be detached. Therefore, when instantiated with
  720.    an integer, these two versions have the same signature,
  721.    which is what causes the error. Integer types aren't
  722.    allowed here due to resulting ambiguity between the
  723.    type and the index of the Bag or Array.
  724.  
  725. Q: How come bioscom() doesn't work on my computer?
  726. A: The bioscom() function uses DOS interrupt 0x14
  727.    directly, and thus bioscom()'s functionality is
  728.    tied directly to the BIOS of your computer. MS-DOS
  729.    support for the serial communications port might be 
  730.    inadequate in several respects for high-performance
  731.    serial I/O applications. First, MS-DOS provides no
  732.    portable way to test for the existence or status of
  733.    a particular serial port in a system. If a program
  734.    "opens" COM2 and writes data to it, and the physical
  735.    COM2 adapter isn't present in the system, the
  736.    program may simply hang. Similarly, if the serial port
  737.    exists, but no character has been received and the
  738.    program attempts to read a character, the program
  739.    hangs until one is available. There is no traditional
  740.    function call to check if a character is waiting.
  741.    MS-DOS also provides no portable method to initialize
  742.    the communication adapter to a particular baud rate,
  743.    word length, and parity. An application must resort
  744.    to ROM BIOS calls, manipulate the hardware directly,
  745.    or rely on the user to configure the port properly with 
  746.    the MODE command before running the application that
  747.    uses it. Because of all the problems mentioned above,
  748.    we strongly recommend getting a third party
  749.    communications package when attempting to do
  750.    serial communications, or downloading the 
  751.    example program SERIAL.ZIP from our BBS at
  752.    (408) 439-9096.
  753.  
  754. Common Windows and ObjectWindows Questions
  755. ------------------------------------------------------------
  756. Q: How do I convert my old OWL 1.0 to OWL 2.5?
  757. A: You can use a utility called OWLCVT to help you do this.
  758.    This utility is documented in the ObjectWindows for C++
  759.    Programmer's Guide.
  760.  
  761. Q: How do I get OWL 1.0 to work with BC 5.0?
  762. A: The on-line file, COMPAT.TXT, provides information on
  763.    doing this.
  764.  
  765. Q. Why isn't my DLL working correctly?
  766. A. One possibility is that you are not linking in the
  767.    correct 'cw' library. If you are building a small
  768.    model DLL, you should be using cwc, not cws. If you are
  769.    building a medium model DLL, you should be using cwl,
  770.    not cwm. Compact and large models should use cwc
  771.    and cwl respectively.
  772.  
  773. Q. Why isn't my program working correctly?  I'm getting a
  774.    message box from Windows saying "Unrecoverable
  775.    Application Error".
  776. A. One possible answer is that the program was not built
  777.    correctly. For example, the linker didn't get the correct
  778.    information to export functions. Diagnostic messages from
  779.    the linker could indicate this. To check that you have
  780.    built your program on DLL as expected, review the
  781.    section in the Programmer's Guide that deals
  782.    with exports. This section has a table with eight
  783.    columns describing the possible combinations you might
  784.    have used to build your program. If the setup of your
  785.    program corresponds to one of the last three columns, 
  786.    chances are that your program was not built correctly 
  787.    (or, at least, as you intended). Column 5 corresponds
  788.    to the 'classical' method of building Windows programs.
  789.    That is, all exports are declared in the module
  790.    definition file (the .def file).
  791.  
  792.    The columns that use -WE or -WDE will build 'better'
  793.    code in the sense that the compiler won't make 'exportable'
  794.    any functions that it doesn't actually export.
  795.    However, it is here that many people run into
  796.    problems. If you have any functions declared as exports
  797.    in the .def file but the module is compiled with
  798.    -WE or -WDE, then you probably have built the program 
  799.    incorrectly (the function will be exported only if it
  800.    is preceded by _export in the source code).
  801.  
  802. Q. How do I use the _export key word?
  803. A. Put the "_export" immediately before the function name
  804.    in the function declaration to export that function.
  805.    Here is a quick example:
  806.       long FAR PASCAL _export func(void) {...}
  807.  
  808. Q. I run BCW.EXE and get the error message:
  809.      Fatal: <filename>.def (<line #>): syntax error
  810. A. Check your DATA statement on line number # in
  811.    <filename>.DEF for the correct code (DATA PRELOAD).
  812.  
  813. Q. Why do I get a 'suspicious pointer conversion'
  814.    warning or 'cannot convert' error (in C++ code)
  815.    when I try to use the address of my window
  816.    procedure or call back function?
  817. A. Windows 3.1 has introduced a new type, WNDPROC, which
  818.    takes the place of the FARPROC type in some cases,
  819.    such as the data type of the lpfnWndProc member of
  820.    the WNDCLASS structure. If you are getting a warning
  821.    or error when setting up a WNDCLASS structure that
  822.    is passed to RegisterClass(), use a WNDPROC cast to
  823.    resolve the type mismatch. If you were previously
  824.    using a FARPROC cast, simply change it to a WNDCLASS
  825.    cast. For example,
  826.     void FAR PASCAL f(void);
  827.     WNDCLASS wcTemp;
  828.     wcTemp.lpfnWndProc = f;         
  829.                 // Warning in C or error in C++
  830.     wcTemp.lpfnWndProc = (FARPROC)f;
  831.                 // Windows 3.0 style type cast
  832.     wcTemp.lpfnWndProc = (WNDPROC)f;
  833.                 // Windows 3.1 style type cast
  834.  
  835. Q. How can I use the features of Windows 3.1 in my
  836.    applications?
  837. A. There are a number of examples that use the
  838.    features of Windows 3.1, such as OLE, DDEML
  839.    and Common Dialogs. There are also lengthy
  840.    descriptions of programming techniques for the
  841.    features of Windows 3.1 in the online Help files.
  842.  
  843. Q. Why don't some of the Windows 3.1 API functions, such as
  844.    ChooseColor(), do anything when I call them?
  845. A. The Windows 3.1 functions that take structures as
  846.    parameters require that the size field of the structure
  847.    be initialized to the size of the structure. This
  848.    technique allows for backward compatibility in future
  849.    versions of these functions. If the size field isn't set
  850.    correctly the function won't do anything. For example,
  851.  
  852.    CHOOSECOLOR ccTemp;                // Data structure
  853.    ccTemp.lStructSize=sizeof(ccTemp); // Set the size first!
  854.    if(ChooseColor(&ccTemp)!=0) etc... // Then call the function
  855.  
  856. Q. Why is my DDEML application crashing?
  857. A. DDEML can crash in seemingly random ways if the
  858.    conversation handle or application instance identifier
  859.    is incorrect or corrupted. Use TDW to watch the value
  860.    of the conversation handle and the application instance
  861.    identifier. If it changes, is corrupted, or you
  862.    inadvertently pass the DDE Management Library an invalid 
  863.    value, that particular call might not fail but DDEML 
  864.    might become unstable and crash at some time in the
  865.    future. Also note that before DdeInitialize() is called
  866.    for the first time, the application instance identifier
  867.    argument MUST be set to 0.
  868.  
  869. Integrated Environment and Resource Workshop
  870. ------------------------------------------------------------
  871. Q:  How do I use Source Pools?
  872. A:  A sample project called srcpool.ide in the 
  873.     \examples\ide\srcpool subdirectory shows you how.
  874.  
  875. Q:  How can I create multitarget programs?
  876. A:  An example project called multitarg.ide in the
  877.     \examples\ide\multitarg subdirectory show you how.
  878.  
  879. Q:  How can I take advantage of Style Sheets?
  880. A:  A sample project called stylsht.ide in the
  881.     \examples\ide\stylsht subdirectory shows you how.
  882.  
  883. Q. Why can't Borland C++ find any of my #include files?
  884. A. The compiler searches for include files in the Include
  885.    Directories path. You can specify this path by selecting
  886.    Options|Project|Directories. The INSTALL program initially
  887.    sets this path to the directory where it copied all the
  888.    Borland C++ *.h files.
  889.  
  890. Q. How do I get Borland C++ to link in my own libraries
  891.    or use multiple source files?
  892. A. Borland C++'s Project Manager is designed to let you
  893.    work with multiple files.
  894.  
  895. Q. Why does Borland C++ report "Unable to open include
  896.    file 'stdarg.h'" when I try to #include <stdio.h>?
  897. A. The most probable reason is that you need to check to
  898.    ensure you have correctly specified the path to your
  899.    include directories by selecting Options|Project|
  900.    Directories and examining the Source
  901.    Directories|Include section.
  902.  
  903.    One other possible reason is that you have exceeded the
  904.    number of files that DOS can have open simultaneously.
  905.    Add the line  FILES=40  to your DOS CONFIG.SYS file.
  906.    This lets DOS open up to 40 files at the same time.
  907.    CONFIG.SYS will only be effective after you have
  908.    rebooted your computer. See the IBM DOS Reference
  909.    Manual for details on the CONFIG.SYS file.
  910.  
  911. Q. When I Make, Run, or Trace a program, Borland C++
  912.    sometimes goes through the compile and link process
  913.    even when the object files are up-to-date.
  914. A. Borland C++'s MAKE logic works solely on a file's date
  915.    and time stamp. If one of your source files is marked
  916.    with a date that's sometime in the future, the object
  917.    files that are created from it will always be older
  918.    than the source file, and Borland C++ will always try
  919.    to rebuild the file. You can fix this by using
  920.    TOUCH.COM to set the file to the current date
  921.    and time. You should also make sure that your system's
  922.    date and time are always properly set. TOUCH.COM is
  923.    documented in the User's Guide chapter on MAKE.
  924.  
  925. Q. How can I convert my earlier project files to the new
  926.    IDE format?
  927. A. Using Project|Open, select "3.1 Project Files (*.prj)"
  928.    into "List Files of Type" drop-down box. Select the 3.1
  929.    project you want to run--the project is automatically
  930.    converted into *.ide format. The original *.prj file
  931.    remains unchanged. Be sure to save the new *.ide file.
  932.  
  933. Q. How can I find out where my "null pointer assignment"
  934.    is occurring?
  935. A. Set a watch on the following expressions:
  936.             *(char *)0,4m
  937.             (char *)4
  938.  
  939.    Step through the program. When the values change, the
  940.    just-executed line is the one causing the problem.
  941.  
  942. Q. When I try to load a new file after editing a file,
  943.    the first file remains on the screen. How do I close
  944.    the first file?
  945. A. Use Ctrl-F4 to close the current file.
  946.  
  947. Q. I'm doing a search and replace operation and the editor
  948.    prompts me for each replacement. I've selected "Change
  949.    All", but it still does it.
  950. A. To disable the prompting, you must unselect the
  951.    "Prompt on replace" option on the left side of the
  952.    Search dialog box.
  953.  
  954. Q. When I try to use any of the pseudo registers, like
  955.    _AX, I get the error message "Undefined symbol '_AX' in
  956.    function..." when I compile. Why?
  957. A. You are only allowed to use the pseudo registers in
  958.    the Borland C++ and ANSI modes of the compiler. You can
  959.    change this setting by selecting Options|Project|
  960.    Compiler|Source.
  961.  
  962. Q: How do I stop all of the files I have ever edited
  963.    from constantly being open when I start Borland C++?
  964. A: By default, Borland C++ saves what is called the
  965.    desktop configuration. This configuration is saved
  966.    in a file with a .DSW extension. By deleting any files
  967.    of this type (usually located in the current directory
  968.    and/or the BC5\BIN directory), then entering
  969.    Options|Environment|Preferences and unchecking the
  970.    'auto save desktop' option, you'll begin with a
  971.    clean desktop each time you start Borland C++.
  972.  
  973. Q: How do I view 32-bit registers in the debugger?
  974. A: Add the appropriate 32-bit register pseudovariable
  975.    to the Watch window. For example, if you were
  976.    interested in the value of EAX, you'd add _EAX to
  977.    the Watch window.
  978.  
  979. Q: Why does Resource Workshop say "Cannot open file" on
  980.    a header file I included in my .RC or .DLG file?
  981. A: Either the file doesn't exist, or Resource Workshop
  982.    doesn't know what directory to look for it. See if
  983.    the file exists. If it does, then add the directory
  984.    name to the Include Path under File|Preferences.
  985.  
  986. Q: Why is the Include Path disabled when I look under
  987.    File|Preferences in Resource Workshop?
  988. A: The Include Path is disabled when a project is
  989.    opened. Close the project and then change the path.
  990.  
  991. Q: In Resource Workshop, why can I select only bold fonts
  992.    when I'm in the dialog editor?
  993. A: This is a limitation of Windows, not Resource Workshop.
  994.    Currently, Windows allows only bold fonts in dialog
  995.    templates. You can send WM_SETFONT messages while
  996.    your program is running if you want other fonts or styles.
  997.  
  998. Q: Why does my dialog paint funny when I select Test mode?
  999.    The menu and/or the minimize/maximize buttons don't
  1000.    draw correctly.
  1001. A: Again, this is a limitation of Windows. There are
  1002.    certain styles for a dialog box that shouldn't be
  1003.    combined. Namely, the Modal Frame style can cause
  1004.    painting problems when combined with the Min/Max
  1005.    buttons or menus.
  1006.  
  1007. Q: I did everything the documents suggested, but
  1008.    Resource Workshop still doesn't work or behaves
  1009.    strangely. Why?
  1010. A: Look for any .RWS files and delete them. These files
  1011.    are maintained by Resource Workshop and can cause
  1012.    unusual behavior in Resource Workshop if they become
  1013.    corrupted or out-of-sync with the .RC or .DLG files.
  1014.  
  1015. Command-Line Compilers
  1016. ------------------------------------------------------------
  1017. Q. Why can't Borland C++ find any of my #include files?
  1018. A. The compiler searches for include files in the Include
  1019.    Directories path. You specify this path with the -I
  1020.    option or with Options|Project|Directories in the IDE.
  1021.    The INSTALL program initially writes a configuration
  1022.    file (TURBOC.CFG for BCC.EXE, BCC32.CFG for BCC32.EXE)
  1023.    that sets this path to the directory where it copied all
  1024.    the Borland C++ *.h files. You can edit this file to
  1025.    change the default path, or create this file in your
  1026.    current working directory and place any relevant paths
  1027.    and other command line compiler options in it. A sample
  1028.    .cfg file might contain the following:
  1029.      -ml
  1030.      -IC:\BC5\INCLUDE;C:\BC5\CLASSLIB\INCLUDE
  1031.      -LC:\BC4\LIB;C:\BC5\CLASSLIB\LIB
  1032.  
  1033. Q. Why does the linker tell me that all the graphics
  1034.    library routines are undefined?
  1035. A. BCC won't search the graphics library unless you
  1036.    tell it to. You should specify the graphics library
  1037.    on the command line. For example, to compile BGIDEMO,
  1038.    type BCC BGIDEMO.C GRAPHICS.LIB and press Enter.
  1039.  
  1040. Q. I run BCC.EXE and get the error message:
  1041.    Fatal: <filename>.def (<line #>): syntax error
  1042. A. Check your DATA statement on line number # in
  1043.    <filename>.def for the correct code (DATA PRELOAD).
  1044.  
  1045.  
  1046. General I/O
  1047. ------------------------------------------------------------
  1048. Q. The '\n' in cprintf() doesn't return the cursor to the
  1049.    beginning of the line--it only moves it down one line.
  1050. A. cprintf() interprets '\n' as a Line Feed. To force the
  1051.    cursor to the beginning of the line, manually insert a
  1052.    Carriage Return:
  1053.       cprintf("\n\r");
  1054.  
  1055. Q. How do I print from within a Borland C++ program?
  1056.  
  1057. A:  The answer depends upon two issues:
  1058.       1.  What kind of printer is being used?
  1059.       2.  What environment is targeted by the application?
  1060.    As for printers, the answers below assume the printer  is 
  1061.    accepting simple ASCII sequences.  If you are wanting to print 
  1062.    graphic images and/or using a specialized printer such as PostScript,
  1063.    please consult the printer documentation.
  1064.  
  1065.    For DOS-targeted applications, you can route the output through 
  1066.    the standard DOS file handle 4, or mnemonically, 'stdprn'.  For a C 
  1067.    program, the code would look as follows:
  1068.  
  1069.    #include <stdio.h>
  1070.    int main() 
  1071.    {
  1072.        fprintf(stdprn, "Hello, world!\n");
  1073.        return 0;
  1074.    }
  1075.  
  1076.    For a C++ program, you would code it as follows:
  1077.  
  1078.    #include <fstream.h>
  1079.    #include <stdio.h>
  1080.    int main()
  1081.    {
  1082.        ofstream cprn(fileno(stdprn));
  1083.        cprn << "Hello, world!" << endl;
  1084.        return 0;
  1085.    }
  1086.  
  1087.    For EasyWin applications, please consult TI1717 located on Borland's
  1088.    ftp site, TechFAX, BBS, or CompuServe.  Please consult the "Borland
  1089.    Assist Support Reference" for more information on these locations.
  1090.  
  1091.    For Windows programs, please consult Windows programming 
  1092.    documentation on the subject of device contexts.
  1093.  
  1094.    In addition, Borland C++ uses a FILE pointer (stdprn) defined 
  1095.    in the STDIO.H file. You do not need to open stdprn before
  1096.    using it:
  1097.        #include <stdio.h>
  1098.        int main(void)
  1099.        {
  1100.            fprintf(stdprn, "Hello, printer!\n");
  1101.        }
  1102.  
  1103.    Note that if your printer is line-buffered, the output
  1104.    is flushed only after a '\n' is sent.
  1105.  
  1106. Q. I'm reading and writing binary files. My program is
  1107.    translating the Carriage Return (0x0D) and Line Feed
  1108.    (0x0A) characters. How do I prevent this from happening?
  1109. A. Files opened in text mode will translate these characters
  1110.    for DOS. To read a file in binary mode, open it in binary
  1111.    mode. For example,
  1112.      #include <stdio.h>
  1113.      int main(void)
  1114.      {
  1115.        FILE *binary_fp;
  1116.        char buffer[100];
  1117.  
  1118.        binary_fp = fopen("MYFILE.BIN", "rb");
  1119.        fread(buffer, sizeof(char), 100, binary_fp);
  1120.                     :
  1121.      }
  1122.  
  1123.    The default file mode is text.
  1124.  
  1125. Q. Why don't printf() and puts() print text in color
  1126.    in a DOS application?
  1127. A. Use the console I/O functions cprintf() and cputs()
  1128.    for color output, as shown here:
  1129.      #include <conio.h>
  1130.      int main()
  1131.      {
  1132.         textcolor(BLUE);
  1133.         cprintf("Hello, world!");
  1134.         return 0;
  1135.      }
  1136.  
  1137. Q. How do I print a long integer?
  1138. A. Use the "%ld" format:
  1139.       long int l = 70000L;
  1140.       printf("%ld", l);
  1141.  
  1142. Q. How do I print a long double?
  1143. A. Use the "%Lf" format.
  1144.       long double ldbl = 1E500;
  1145.       printf("%Lf", ldbl);
  1146.  
  1147.  
  1148. Graphics (DOS)
  1149. ------------------------------------------------------------
  1150. Q. Why do I get the error message:
  1151.    BGI Error: graphics not initialized (use 'initgraph')
  1152.    when I use a graphics function? My program has already
  1153.    called initgraph().
  1154. A. For some reason initgraph() failed. To find out why,
  1155.    check the return value of graphresult(). For example:
  1156.       #include <graphics.h>
  1157.       int main(void)
  1158.       {
  1159.         int gerr;   /* graphics error */
  1160.         int gdriver = DETECT, gmode;
  1161.  
  1162.      // Initialize graphics using auto-detection and look
  1163.      // for the .BGI and .CHR files in the C:\BC5\BGI
  1164.      // directory.
  1165.         initgraph(&gdriver, &gmode, "C:\\BC5\\BGI");
  1166.  
  1167.         if ((gerr = graphresult()) != grOk)
  1168.         {
  1169.             printf("Error : %s\n", grapherrormsg(gerr));
  1170.             exit(1);
  1171.         }
  1172.                :
  1173.       }
  1174.  
  1175. Math and Floating Point
  1176. ------------------------------------------------------------
  1177. Q. Why do I get incorrect results from all the math library
  1178.    functions like cos(), tan() and atof()?
  1179. A. You must #include <math.h> before you call any of the
  1180.    standard Borland C++ math functions. In general, Borland
  1181.    C++ assumes that a function that isn't declared returns
  1182.    an int. In the case of math functions, they usually
  1183.    return a double. For example
  1184.    /* WRONG */                       /* RIGHT */
  1185.                                      #include <math.h>
  1186.    int main(void)                    int main(void)
  1187.    {                                 {
  1188.     printf("%f", cos(0));             printf("%f", cos(0));
  1189.    }                                 }
  1190.  
  1191. Q. How do I "trap" a floating-point error?
  1192. A. See the signal() and matherr() functions in the Borland
  1193.    C++ Library Reference. The signal() function might be
  1194.    used to trap errors in the 80x87 or the 80x87 emulator.
  1195.    The matherr() function traps errors in the Math Library
  1196.    functions.
  1197.  
  1198. Linker Errors
  1199. -------------------------------------------------------------
  1200. Q. I am linking C functions in a C++ application. The linker
  1201.    reports that all of my C functions are undefined. Why?
  1202. A. To facilitate function overloading as a feature in C++, 
  1203.    the compiler takes the name of the function along with the 
  1204.    types of its parameters, and creates an internal mangled name 
  1205.    to differentiate this function from another by the same name but 
  1206.    with different arguments.  
  1207.  
  1208.    This same mangled name is also used by the linker.
  1209.    Functions compiled as C code are not mangled in 
  1210.    the same manner as functions compiled as C++ code (Use 
  1211.    the TDUMP utility to determine the exact names involved.).  
  1212.    The linker cannot resolve these differences;  it is up to the 
  1213.    programmer to programmer to modify how name mangled occurs.
  1214.  
  1215.    For the case where C functions are required within a C++ 
  1216.    program, simply change to function prototypes with the 
  1217.    modifier extern "C".  That is, assume that the following 
  1218.    function prototypes denote the function signatures for two 
  1219.    functions compiled as C code:
  1220.  
  1221.    char *StringCopy(char*, char*);
  1222.    void ClearScreen(void);
  1223.  
  1224.    To make these functions callable within a C++ application, 
  1225.    instruct the C++ compiler to not mangle their names when they 
  1226.    are prototyped in a C++ module.  For example:
  1227.  
  1228.    extern "C" char *StringCopy(char*, char*);
  1229.    extern "C" void ClearScreen(void);
  1230.  
  1231.    Likewise, both prototypes can be placed in a single block:
  1232.  
  1233.    extern "C" {
  1234.        char *StringCopy(char*, char*);
  1235.        void ClearScreen(void);
  1236.    }
  1237.  
  1238.    As for the other case where C code is calling C++ functions, 
  1239.    the programmer may not have many options.  In many cases, the 
  1240.    programmer can use the extern "C" modifier in the definition of 
  1241.    the C++ functions.  This, however, will effect whether 
  1242.    overloaded functions can still exist (Name uniqueness may be lost.).
  1243.    Another alternative is to write a simple assembly language module 
  1244.    that will translate between the C function names and the C++ 
  1245.    mangled function names (which are not legal C names).
  1246.  
  1247. Q. Why do I get the following message when creating a DOS 
  1248.    application:
  1249.    "Linker Error: Unable to open input file 'C0x.OBJ'"
  1250. A. The linker searches for Borland C++ start-up and library
  1251.    files in the Borland C++ Library Directories path. You can
  1252.    specify this path by selecting the Options|Directories.
  1253.    The INSTALL program initially sets this path to the
  1254.    directory where it copied the start-up and library
  1255.    files. Also be sure that you installed the memory model
  1256.    that the linker is looking for. The 'x' in the error
  1257.    message corresponds to the memory model, e.g. 's' 
  1258.    for small, 'l' for large, etc.
  1259.  
  1260. Q. Why do I get the following message when creating a DOS 
  1261.    application:
  1262.    Linker Error: Undefined symbol '_main' in module C0
  1263. A. Every C program must contain a function called main().
  1264.    This is the first function executed in your program.
  1265.    The function name must be all in lower case. If your
  1266.    program doesn't have one, create one. If you're using
  1267.    multiple source files, the file that contains the
  1268.    function main() must be one of the files in the Project.
  1269.    Note that an underscore character '_' is prefixed to
  1270.    all external Borland C++ symbols.
  1271.  
  1272. Q. Why does the linker tell me that all the graphics 
  1273.    library routines are undefined in my DOS application?
  1274. A. See the "Integrated Environment" and "Command-line
  1275.    Compiler"  sections above.
  1276.  
  1277. Q. What is a 'Fixup overflow'?
  1278. A. This usually means you're attempting to link object
  1279.    files that weren't all compiled under the same memory
  1280.    model.  Publication TI1150, "Coping with Fixup
  1281.    Overflow Messages", provides more information. It is
  1282.    available as TI1150.ZIP on Borland's Download BBS
  1283.    (408)431-5096, and as document # 1150 on Borland
  1284.    Techfax (800) 822-4269.
  1285.  
  1286. Q. I'm linking my own assembly language functions with
  1287.    Borland C++. The linker reports that all of my
  1288.    functions are undefined.
  1289. A. Make sure that you have put an underbar character '_'
  1290.    in front of all assembly language function names to
  1291.    be called by Borland C++. Your assembly language
  1292.    program should be assembled with Case Sensitivity.
  1293.    If compiling as C++ (rather than C), see the "Common
  1294.    C++ Questions" section above for a discussion of
  1295.    extern "C".
  1296.  
  1297. Q: I'm getting an error from the linker "segment group
  1298.    exceeds 64K :  _text" in my DOS application.
  1299. A: If you're using the BGIOBJ utility, the default segment
  1300.    into which the objects will be place is _text. You
  1301.    should try using BGIOBJ with the /f option to place
  1302.    the resultant objects into a separate segment.
  1303.    You'll then need to use the functions registerfarbgidriver
  1304.    and registerfarbgifont to register the objects for the
  1305.    graphics system. See UTILS.TXT for instructions on
  1306.    using these functions. In addition, publication TI703,
  1307.    "Resolving 'Segment or Group xxxx Exceeds 64K',
  1308.    provides more information on this issue. It is availble
  1309.    as TI703.ZIP on Borland's Download BBS (408)431-5096,
  1310.    and as document #703 on Borland Techfax (800) 822-4269.
  1311.  
  1312. Q: Why am I getting the error "printf: floating point
  1313.    formats not linked"?
  1314. A: You probably have your libraries out of order on the
  1315.    TLINK command line. (See the User's Guide for TLINK
  1316.    syntax.) For example, if you are using the large
  1317.    memory model and BGI routines, the TLINK line might
  1318.    look like the following:
  1319.      tlink /v c0l myobj,,,mylib graphics emu mathl cl
  1320.    If the object file or library isn't in the current
  1321.    directory, the complete pathname must be supplied.
  1322.    Frequently this causes the command line to exceed
  1323.    128 characters (you'll need to use a response file--
  1324.    See the User's Guide).
  1325.  
  1326. Q. I'm porting an application that uses communal
  1327.    variables to C++. I've set up the compiler to
  1328.    recognize them, but I still get linker errors:
  1329.    Error: <name> defined in module <a> is duplicated
  1330.    in module <b>
  1331. A. C++ doesn't support explicit COMDEFs; you must use
  1332.    static variables or switch to C.
  1333.  
  1334. Other Questions
  1335. ------------------------------------------------------------
  1336. Q. I get a "floating point formats not linked" message when
  1337.    I run my program. What can I do about it?
  1338. A. Floating point formats (for scanf() and related functions)
  1339.    aren't always linked, for savings in executable size. To
  1340.    force their inclusion, put the following somewhere in your
  1341.    source files:
  1342.       extern int _floatconvert;
  1343.       #pragma extref _floatconvert
  1344.  
  1345. Q. How do I change the stack size?
  1346. A. In a DOS program, the size of the stack of a Borland C++
  1347.    program is determined at run time by the global variable
  1348.    _stklen. For example, to change the size to 10,000 bytes,
  1349.    include the following line in your program:
  1350.       extern unsigned _stklen = 10000;
  1351.    This statement must not be inside any function definition.
  1352.    The default stack size is 4,096 bytes (4K), and you might
  1353.    increase the stack to 65519 (0xFFEF) or just under 64K
  1354.    in the compact, large, or huge memory models.
  1355.  
  1356.    In a Windows Program, the size of the stack is controlled
  1357.    by the STACKSIZE line of the module definition (.DEF) file.
  1358.    See the Programmer's Guide and the User's Guide for
  1359.    more information on module definition files.
  1360.  
  1361. Q. I'm getting a 'Stack Overflow!' message when I run my
  1362.    program. How can I work around this?
  1363. A. If you are using the compact, large, of huge memory models,
  1364.    you might increase the stack size by following the
  1365.    procedure above. In the smaller memory models, your only
  1366.    option is to decrease the amount of stack space or near
  1367.    heap space used in your program. Stack overflows are
  1368.    usually caused by a large amount of local data or
  1369.    recursive functions. You can decrease the amount of stack
  1370.    space used in several ways:
  1371.    1) By declaring your local variables static (see the
  1372.       Programmer's Guide for the effects of using the 
  1373.       "static" keyword):
  1374.         int main(void)                int main(void)
  1375.         {                             {
  1376.          char x[5000];     -->          static char x[5000];
  1377.             :                                :
  1378.         }                             }
  1379.    2) By making your variables global rather than local:
  1380.         char x[5000];    //global allocation above main()
  1381.         int main(void)
  1382.         {
  1383.                :
  1384.         }
  1385.    3) By allocating your variables dynamically off the
  1386.       far heap:
  1387.       #include <alloc.h>
  1388.       int main(void)
  1389.       {
  1390.        char far* x;
  1391.        x = (char far*)farmalloc(5000);  //dynamic allocation
  1392.        // or in the case of C++ you can use the new operator
  1393.        // x = new char[5000];
  1394.            :
  1395.       }
  1396.  
  1397. Q. My program comes up with the message 'Null pointer
  1398.    assignment' after it terminates. What does this mean?
  1399. A. Before a small-data model Borland C++ program returns
  1400.    to DOS, it checks to see if the beginning of its data
  1401.    segment has been corrupted. This message warns you that
  1402.    you have used uninitialized pointers or that your
  1403.    program has corrupted memory in some other way.
  1404.  
  1405. Q. Why do I get "declaration syntax error" messages on dos.h?
  1406. A. You have set the "ANSI keywords only" option ON. Keep this
  1407.    option OFF when using any keywords specific to Borland C++. 
  1408.    See the Programmer's Guide for a list of keywords.
  1409.  
  1410. Q. I get errors when compiling the windows.h header file. Why?
  1411. A. Be sure that you have "Borland Extensions" selected as your
  1412.    keywords option. This option can be toggled under
  1413.    Options|Project|Compiler|Source in the IDE. It is on by
  1414.    default in the command-line compilers (-AT or -A-).
  1415.  
  1416. Q. I have a working program that dynamically allocates memory
  1417.    using malloc() or calloc() in small data models (tiny,
  1418.    small, and medium). When I compile this program in large
  1419.    data models (compact, large, and huge), my program hangs.
  1420. A. Make sure that you have #include <alloc.h> in your program.
  1421.  
  1422. Q. I'm linking my own assembly language functions with Borland
  1423.    C++, but the linker reports that all of my functions are
  1424.    undefined. Why?
  1425. A. See answer above in the "Linker" section.
  1426.  
  1427. Q. My far pointers "wrap around" when they are incremented
  1428.    over 64K. How do I reference a data object that is
  1429.    greater than 64K?
  1430. A. Use huge pointers.
  1431.  
  1432. Q. How do I get Clipper to link with Borland C++?
  1433. A. If you have trouble, contact Nantucket Technical Support.
  1434.  
  1435. Q. I'm trying to build an app based on one of Borland's
  1436.    libraries (ObjectWindows, the container classes 
  1437.    in the CLASSLIB directory, or the Run-time Library),
  1438.    and I get linker errors, or it won't run right.
  1439.    What's going wrong?
  1440. A. You might be using a switch that affects linkage in
  1441.    your files that wasn't used when the library itself
  1442.    was compiled, or you need to change the library in
  1443.    question. Here are some examples:
  1444.    - If you use far vtables (-Vf or Options|Project|
  1445.      Compiler|C++|Far virtual tables) to compile a file
  1446.      you developed which includes iostream.h, it won't
  1447.      build correctly until you rebuild the iostream
  1448.      library with the same option.
  1449.    - If you opt to use the templates implementation of
  1450.      the container class library to build ObjectWindows
  1451.      applications, you must rebuild the necessary
  1452.      ObjectWindows libraries from source using the
  1453.      templates implementation of the class library
  1454.     (the BIDxxxx.LIB files.)
  1455.  
  1456. Q. I got a "bad call to intrinsic function" message when
  1457.    compiling one of my source files. What does this mean?
  1458. A. This message appeared because you tried to use an
  1459.    intrinsic function in a small model DLL. Either avoid
  1460.    using intrinsic functions in your DLL, or turn off
  1461.    the -Oi and -O2 switches (Options|Project|
  1462.    Optimizations Speed|Inline Intrinsic Functions).
  1463.  
  1464. Q: I open up a file in append mode and append some data
  1465.    to the end of the file. When I look at the data in an
  1466.    ASCII editor, I can't see the appended data. Why?
  1467. A: The data is being appended after the End-of-File mark,
  1468.    and the ASCII editor isn't displaying the data after
  1469.    the EOF mark. To eliminate the EOF mark:
  1470.    1) Get the file length with the filelength() function:
  1471.        FILE *file_pointer = fopen("file.nam","a");
  1472.        long length = filelength(fileno(file_pointer));
  1473.    2) Use the chsize() function to change the file
  1474.       length to the current length-1:
  1475.        chsize(fileno(file_pointer), (length -1));
  1476.    3) Then write your appended data to the file.
  1477.  
  1478. Q: I run my DOS program, allocate some memory, and check the
  1479.    amount of memory available with coreleft(). Then I
  1480.    free some memory and call coreleft() again. It reports
  1481.    the same number. Why?
  1482. A: Coreleft does NOT return the amount of memory available.
  1483.    It returns the total memory available above the highest
  1484.    block allocated. It does NOT return any amount of memory
  1485.    available in "holes" below the highest allocated block.
  1486.    The code for a function that returns the amount of total
  1487.    free memory is provided in the document TI1723. This
  1488.    document is available on Borland's Download BBS, 
  1489.    (408)431-5096, as document # 1723, and on Borland
  1490.    Techfax, (800) 822-4269, as TI1723.ZIP.
  1491.  
  1492. -------------------END OF FILE HELPME.WRI-------------------
  1493.